package main

import (
	"fmt"
	"math"
)

func varScope3() {
	var local1, loacl2 int
	var global int = 1

	local1 = 8
	loacl2 = 10
	global = local1 + loacl2
	const (
		pi float32 = math.Pi
	)

	if loacl2 > 10 {

	} else if loacl2 > 11 {

	} else {

	}

	for i := 1; i < local1; i++ {
		loacl2 = loacl2 + i
	}
	//无限循环
	/*for{


		}
	}*/

JumpLoop:
	for j := 1; j <= 5; j++ {
		for i := 1; i < 5; i++ {
			if i > 2 {
				break JumpLoop
			}
		}
	}

	for key, val := range []int{0, 1, 2, 3, 4} {
		fmt.Printf("key:%d,vaule:%d\n", key, val)
	}
	/*创建集合 */
	var countryCapitalMap map[string]string
	countryCapitalMap = make(map[string]string)
	/* map插入key - value对,各个国家对应的首都 */
	countryCapitalMap["France"] = "巴黎"
	countryCapitalMap["Italy"] = "罗马"
	countryCapitalMap["Japan"] = "东京"
	countryCapitalMap["India "] = "新德里"
	/*使用键输出地图值 */
	for country := range countryCapitalMap {
		fmt.Println(country, "首都是", countryCapitalMap[country])
	}

	var love = "love"
	switch love {
	case "love":
		fmt.Println("love")
	case "meta":
		fmt.Println("meta")
	default:
		fmt.Println("meta")
	}
	fmt.Printf("local1 = %d,local2 = %d,global = %d,pi = %d\n", local1, loacl2, global, pi)
}

func gotoDemo() {
	var isBreak bool
	for i := 0; i < 20; i++ {
		for j := 0; j < 20; j++ {
			if j == 2 {
				isBreak = true
				break
			}
			if j == 3 {
				goto breakTag
			}
		}
		if isBreak {
			break
		}
	}
	fmt.Println("over!")
breakTag:
	fmt.Println("over!breakTag")
}

func boolToInt(b bool) int {
	if b {
		return 1
	}
	return 0
}
